package jui.business
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.text.StyleSheet;
	
	import jui.maps.events.DataReadyEvent;

	public class StyleManager extends EventDispatcher implements IJUIManager
	{
		/** 
		 * CSS Loaded here defines the styles for message window
		 */
		private var styleSheet:StyleSheet;
		private var urlLoader:URLLoader;

		/**
		 * Returns qualified class name used by ManagersFacrtory to produce this manager.
		 */
		public static function getQName(): String 
		{
			return "jui.business.StyleManager";	
		}
		
		
		public function loadStyleSheet():void {
			urlLoader = new URLLoader();
			urlLoader.addEventListener(Event.COMPLETE, urlLoader_complete);
			urlLoader.load(new URLRequest("assets/styles.css"));
		}
		
		private function urlLoader_complete(evt:Event):void 
		{
			trace("Styles loaded");
			
			var css:String = URLLoader(evt.currentTarget).data;
			// Convert text to style sheet.
			styleSheet = new StyleSheet();
			styleSheet.parseCSS(css);
			// Set the style sheet.
			
			var event: DataReadyEvent = new DataReadyEvent(DataReadyEvent.DATA_READY);
			event.data = styleSheet;
			dispatchEvent(event);
		}		
		
		public function StyleManager()
 		{
 		}
	}
}